//2009/08/04 21:31:38
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

class Substitute
{
public:
    int getValue(string key, string code)
    {
        int score = 0;
        for (int i=0; i<code.size(); i++)
        {
            if (key.find(code[i]) == -1) continue;
            if (code[i] == key[key.size()-1]) score *= 10;
            else
            {
				int pos = key.find(code[i]);
				score = score * 10 + pos + 1;
            }
        }
		return score;
    }
};
